﻿using System;
using System.Collections.Generic;
using System.Windows;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using Telerik.Windows.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCL.UI.PopWindows;
using System.Windows.Controls;
using Telerik.Windows.Controls.GridView;

namespace Baosight.ZNH.ZMCL.UI
{
    /// <summary>
    /// 待反馈三违记录
    /// </summary>
    /// Title:ZMCL81
    /// Service:ServiceZMCL81
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2011-06-24   高强   [创建]
    ///  
    public partial class ZMCL81 : EFViewCmes
    {
        public ZMCL81()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 修改前设置属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(Platform.Core.EIInfo initData)
        {
            base.Initialize(initData);
        }

        /// <summary>
        /// “反馈”按钮执行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnFeedBackButtonClick(object sender, RoutedEventArgs e)
        {
            IList<EIRow> _list = this.grid.GetCheckedEIRows() == null ? new List<EIRow>() : this.grid.GetCheckedEIRows();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");

            EIRow row = new EIRow();
            if (_list.Count > 0)
            {
                row = BaseTools.GetEIRowByOldEIRow(this.EIDataContext.GetBlock("result").GetColumns(), _list[0]);
            }
            eIBlock.SetRow(0, row);
            eiInfo.AddBlock(eIBlock);
            base.OnUpdateButtonClickPopup("反馈", eiInfo, "三违记录-反馈", "insert", null, sender, e);
        }

        /// <summary>
        /// 新增或修改之前的数据传输
        /// 构造新增页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        public override void OpenPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {

            TernateFeedback _feedback = new TernateFeedback(_dialogType);//构造一个新的修改页面
            
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.department"));//传递责任单位block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.sourceClassify"));//传递三违来源block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.classify"));//传递三违分类block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.roadWay"));//传递巷道block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.workFace"));//传递工作面block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.responsibilityPeople"));//添加检查人block

            _feedback.EIDataContext = new Platform.Core.UI.EIDataContext();
            _feedback.EIDataContext.Update(_eIInfo);

            _feedback.fdFeedbackPeopleId.Value = this.EIDataContext.GetAttribute("fdFeedbackPeople").ToString();

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(CmesWindow_Closed);
            _popup.Content = _feedback;//让处理页面在弹出窗口显示
            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmesWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            //按钮生效
            base.TempButtonOpen(true);

            if (e.DialogResult == true)
            {
                //刷新Grid区域
                this.grid.Refresh();
            }
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PopupWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }

        /// <summary>
        /// 主表记录选择发生改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void grid_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if (null != this.grid.SelectedItem)
            {
                EIRow _row = (this.grid.SelectedItem as UIBaseEntity).GetEIRow();
                string fdStatus = _row["fdStatus"] == null ? "" : _row["fdStatus"].ToString();

                Dictionary<string, string> args = new Dictionary<string, string>();
                args.Add("fdTernateRecordId", _row["fdTernateRecordId"].ToString());
                this.deregulationDetails.LoadView<EFCustomViewContainerPanel>("ZMCL63", args);//加载从表页面

                Dictionary<string, string> args1 = new Dictionary<string, string>();
                args1.Add("fdPenaltyIds", _row["fdPenaltyIds"] == null ? "" : _row["fdPenaltyIds"].ToString());
                this.deregulationPenalty.LoadView<EFCustomViewContainerPanel>("ZMCL75", args1);//加载从表页面
            }
            else
            {
                this.deregulationDetails.Content = null;
                this.deregulationPenalty.Content = null;
            }
        }
    }
}
